//实例化表格
layuiFunciton.tableInit({
    toolbar:'.btn',
    tableId: 'activitiExampleTalbe',
    url:  layuiFunciton.URL + '/activiti/workflow/process-list',
    id: 'activitiExampleTalbeId',
    tableFilter:'activitiExampleFilter',  //表格监听名称,
    cols: [[
        {type:'numbers',title: '序号',fixed: 'left'},
        {field: 'name', title: '流程名称', sort: true},
        {field: 'key', title: '流程key', sort: true},
        {field: 'version', title: '版本号', sort: true},
        {field: 'resourceName', title: 'XML文件'/*, event: 'resourceName'*/, sort: true},
        {field: 'diagramResourceName', title: '流程图片', event: 'diagramResourceName', sort: true},
        {field:'deploymentTime', title: '部署时间',templet:function (obj) {
            return layuiFunciton.formatDateTime(obj.deploymentTime);
        }},
        {field:'', title: '流程状态',width:110 , sort: true,templet:function (data) {
            var html = '<input type="checkbox" name="enabled" value="'+data.id+'" lay-skin="switch" lay-text="启用|禁用" lay-filter="enabledSuspended" ' ;
            if(!data.suspended){
                html+='checked';
            }
            html+='>';
            return html;
        }},
        {title: '操作', align:"center",templet: '#activitiModelBar',fixed: 'right'}
    ]],
	returnData:function(data){
		layuiFunciton.uploadFile({
			elem: '#addActivitiExample',
			url:  layuiFunciton.URL + '/activiti/workflow/deploy',
			title:'支持文件格式：zip、bar、bpmn、bpmn20.xml',
			accept:'file',
			ext: 'bpmn20.xml|zip|bar|bpmn',
			done: function(res, index, upload){
				layuiFunciton.refresh('','activitiExampleTalbeId');
			}
		});
	},
    tools:{
        resourceName:function (rowData) {//XML文件
            //layuiFunciton.URL + "/activiti/workflow/resource/read?processDefinitionId=" + rowData.id+"&resourceType=xml"
        },
        diagramResourceName:function (rowData) {//流程图片
            layuiFunciton.layerOpen({
                title: "查看流程图片",
                pageReady:false,
                content: layuiFunciton.URL + "/activiti/workflow/resource/read?processDefinitionId=" + rowData.id+"&resourceType=image"
            });
        },
        daoru:function (rowData) {
            layuiFunciton.ajaxRequest({
                url:  layuiFunciton.URL + '/activiti/workflow/process/convert-to-model/'+ rowData.id,
                method: 'get',
                success: function(data){
                    layuiFunciton.success("操作成功！",function () {
                        layuiFunciton.addTab({
                            title:'流程模型',
                            url:'/page/core/activiti/model/index.html'
                        });
                    });
                }
            });
        }
        ,del:function (rowData) {
            layuiFunciton.alert({types:'confirm',title:'是否删除？',success:function () {
                layuiFunciton.ajaxRequest({
                    url: layuiFunciton.URL + '/activiti/workflow/process/delete',
                    method:'post',
                    data:{deploymentId:rowData.deploymentId},
                    success:function (data) {
                        layuiFunciton.refresh('','activitiExampleTalbeId');
                    }
                });
            }});
        },
		addActivitiExample:function(rowData){
			$("#addActivitiExample").click();
		}
    },filter:[
        {
            types:'form',   //   注：仅支持 from 、table 两种类型  监听 table的 tools 请使用 tools 属性
            filterTypes: 'switch',   //
            filterName: 'enabledSuspended',
            returnData : function (obj) {
                if(obj.elem.checked){
                    layuiFunciton.ajaxRequest({
                        url:  layuiFunciton.URL + '/activiti/workflow/processdefinition/update/active/'+obj.value,
                        method: 'get',
                        success: function(data){
                            layuiFunciton.success("操作成功！")
                        }
                    })
                }else{
                    layuiFunciton.ajaxRequest({
                        url:  layuiFunciton.URL + '/activiti/workflow/processdefinition/update/suspend/'+obj.value,
                        method: 'get',
                        success: function(data){
                            layuiFunciton.success("操作成功！")
                        }
                    })
                }
            }
        }
    ]
});
